return, and/or¶

return¶

blue_trail.py¶

Move Bit along the blue trail. Stop when the blue stops, or when Bit is blocked in front.

No description has been provided for this image
No description has been provided for this image

No description has been provided for this image
No description has been provided for this image

🖌 and¶

In [1]:
print(True and True)
True
In [2]:
print(True and False)
False
In [3]:
print(False and False)
False

blue_trail_and.py¶

🖌 or¶

In [4]:
print(True or True)
True
In [5]:
print(True or False)
True
In [6]:
print(False or False)
False

red_or_green.py¶

If the square is red or green, paint it blue.

No description has been provided for this image No description has been provided for this image

🎨 🖌 Complex logic¶

cross_the_pond.py¶

The green squares above blue are lilypads. They don't jump away as Bit passes by.

The red squares above black are flowers. They don't jump either.

The green squares above black is a frog. It will jump if Bit passes by.

Move Bit to the other side of the pond and clear the frogs.

🐸

No description has been provided for this image No description has been provided for this image

Freedom¶

to_freedom.py¶

Move Bit to the first space open on both sides.

No description has been provided for this image No description has been provided for this image

In [ ]:
%%file for_class/to_freedom.py
from byubit import Bit


def found_freedom(bit):
    return bit.can_move_left() and bit.can_move_right()


@Bit.worlds('freedom')
def go(bit):
    while not found_freedom(bit):
        bit.move()
        
        
if __name__ == '__main__':
    go(Bit.new_bit)

When you hear

Move until condition is true

Think

while not condition:
   bit.move()

NOTES

Strategy for composing a complex condition:

  1. Write a function that determines the condition where Bit should end
  2. while not <function>(bit):

Spiral 🧑🏻‍🎨¶

spiral.py¶

As long as Bit can move forward or left, keep going!

If blocked in front, turn left.

No description has been provided for this image
No description has been provided for this image

NOTES

Draw it out!

What ending condition do we use?

Under what event do we need to turn?

Hurdles 👩🏼‍🎨¶

No description has been provided for this image No description has been provided for this image

No description has been provided for this image No description has been provided for this image

Key Ideas¶

  • return
  • and, or
  • Writing functions for complex logical statements